package com.msxt.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.msxt.dto.DiscussminsukefangEntity;
import com.msxt.mapper.DiscussminsukefangDao;
import com.msxt.result.Query;
import com.msxt.service.DiscussminsukefangService;
import com.msxt.utils.PageUtils;
import com.msxt.view.DiscussminsukefangView;
import com.msxt.vo.DiscussminsukefangVO;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * 民宿客房评论服务实现类
 */
@Service("discussminsukefangService")
public class DiscussminsukefangServiceImpl extends ServiceImpl<DiscussminsukefangDao, DiscussminsukefangEntity>
		implements DiscussminsukefangService {

	@Override
	public PageUtils queryPage(Map<String, Object> params) {
		Page<DiscussminsukefangEntity> page = new Query<DiscussminsukefangEntity>(params).getPage();
		return new PageUtils(this.page(page, new QueryWrapper<>()));
	}

	@Override
	public PageUtils queryPage(Map<String, Object> params, QueryWrapper<DiscussminsukefangEntity> wrapper) {
		// 1. 构造分页参数
		Page<DiscussminsukefangView> page = new Query<DiscussminsukefangView>(params).getPage();

		// 2. 清除可能存在的错误条件
		wrapper.clear();

		// 3. 添加查询条件（示例：按 refid 过滤）
		if (params.containsKey("refid")) {
			wrapper.eq("refid", params.get("refid"));
		}

		// 4. 统一排序（避免重复）
		wrapper.orderByDesc("id");

		// 5. 执行分页查询
		IPage<DiscussminsukefangView> result = baseMapper.selectPageView(page, wrapper);
		return new PageUtils(result);
	}

	@Override
	public List<DiscussminsukefangVO> listVO(QueryWrapper<DiscussminsukefangEntity> wrapper) {
		return baseMapper.listVO(wrapper);
	}

	@Override
	public DiscussminsukefangVO selectVO(QueryWrapper<DiscussminsukefangEntity> wrapper) {
		return baseMapper.selectVO(wrapper);
	}

	@Override
	public List<DiscussminsukefangView> listView(QueryWrapper<DiscussminsukefangEntity> wrapper) {
		return baseMapper.listView(wrapper);
	}

	@Override
	public DiscussminsukefangView selectView(QueryWrapper<DiscussminsukefangEntity> wrapper) {
		return baseMapper.selectView(wrapper);
	}
}